package com.servlet;

import com.dao.BooksConnection;
import com.dao.UpFileConnection;
import com.entity.Book;
import com.entity.UpFile;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;


@WebServlet("/select")
public class UpFileServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            List<UpFile> upFiles = UpFileConnection.selectALl();
            resp.setCharacterEncoding("UTF-8");
            resp.setContentType("text/html;charset=UTF-8");
            StringBuilder html = new StringBuilder("<style>table, tr,td{border:1px solid black;}</style>");
            html.append("<table>" + "<tr>" + "<td>id</td>" + "<td>IP</td>" + "<td>文件名</td>" + "<td>文件类型</td>" + "<td>文件大小</td>" + "<td>修改时间</td>" + "<td>下载路径</td>" + "</tr>");
            for (UpFile upFile: upFiles) {
                html.append("<tr>" + "<td>")
                        .append(upFile.getId()).append("</td>").append("<td>")
                        .append(upFile.getIP()).append("</td>").append("<td>")
                        .append(upFile.getFilename()).append("</td>").append("<td>")
                        .append(upFile.getFiletype()).append("</td>").append("<td>")
                        .append(upFile.getFilesize()).append("</td>").append("<td>")
                        .append(upFile.getFiledata()).append("</td>").append("<td>")
                        .append(upFile.getDownload()).append("</td>").append("</tr>");
            }
            html.append("</table>");
            PrintWriter writer = resp.getWriter();
            writer.write(html.toString());
            writer.flush();
            writer.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

